import { defineStore } from 'pinia'

const useOrderStore = defineStore('order', {
  state: () => ({

    shelvesIds: JSON.parse(localStorage.getItem('orderShelvesIds')) || [],
    ordersIds: JSON.parse(localStorage.getItem('orderOrdersIds')) || [],
    originalIds: JSON.parse(localStorage.getItem('orderOriginalIds')) || [],
    priorityOriginalIds: JSON.parse(localStorage.getItem('orderPriorityOriginalIds')) || [],
    ordersThicknessList: JSON.parse(localStorage.getItem('orderOrdersThicknessList')) || [],
    maxShelves: JSON.parse(localStorage.getItem('orderMaxShelves')) || 0,
    tailLength: JSON.parse(localStorage.getItem('orderTailLength')) || '',
    tailWidth: JSON.parse(localStorage.getItem('orderTailWidth')) || '',
    packageId: JSON.parse(localStorage.getItem('orderPackageId')) || '',
    pdfLayoutRule: JSON.parse(localStorage.getItem('orderPdfLayoutRule')) || '1'
  }),
  actions: {
    setShelvesIds(shelves) {
      this.shelvesIds = shelves
      localStorage.setItem('orderShelvesIds', JSON.stringify(shelves))
    },
    setOrdersIds(orders) {
      this.ordersIds = orders
      localStorage.setItem('orderOrdersIds', JSON.stringify(orders))
    },
    setOriginalIds(originalIds) {
      this.originalIds = originalIds
      localStorage.setItem('orderOriginalIds', JSON.stringify(originalIds))
    },
    setPriorityOriginalIds(priorityOriginalIds) {
      this.priorityOriginalIds = priorityOriginalIds
      localStorage.setItem('orderPriorityOriginalIds', JSON.stringify(priorityOriginalIds))
    },
    setOrdersThicknessList(ordersThicknessList) {
      this.ordersThicknessList = ordersThicknessList
      localStorage.setItem('orderOrdersThicknessList', JSON.stringify(ordersThicknessList))
    },
    setMaxShelves(maxShelves) {
      this.maxShelves = maxShelves
      localStorage.setItem('orderMaxShelves', JSON.stringify(maxShelves))
    },
    setTailLength(tailLength) {
      this.tailLength = tailLength
      localStorage.setItem('orderTailLength', JSON.stringify(tailLength))
    },
    setTailWidth(tailWidth) {
      this.tailWidth = tailWidth
      localStorage.setItem('orderTailWidth', JSON.stringify(tailWidth))
    },
    setPackageId(packageId) {
      this.packageId = packageId
      localStorage.setItem('orderPackageId', JSON.stringify(packageId))
    },
    setPdfLayoutRule(pdfLayoutRule) {
      this.pdfLayoutRule = pdfLayoutRule
      localStorage.setItem('orderPdfLayoutRule', JSON.stringify(pdfLayoutRule))
    }
  }
})

export default useOrderStore
